﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.IO;
using System.Text;
using System.Xml;

public partial class DangKyNTD : System.Web.UI.Page
{
    public static Boolean flagRedirect = false;
    string username;
    string password;
    string fullname;
    string position;
    string email;
    string address;
    string city;
    string phone;
    string mobile;
    string companyName;
    string companyLink;
    string companyDescription;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Headers["SignUpEmployer"] != null)
        {
            username = Request.Form["username"];
            password = Request.Form["password"];
            fullname = Request.Form["fullname"];
            position = Request.Form["position"];
            email = Request.Form["email"];
            address = Request.Form["address"];
            city = Request.Form["city"];
            phone = Request.Form["phone"];
            mobile = Request.Form["mobile"];
            companyName = Request.Form["companyName"];
            companyLink = Request.Form["companyLink"];
            companyDescription = Request.Form["companyDescription"];

            try
            {
                string strCreateAcc = "http://localhost:8080/ViecLamService/CreateEmployerAccount/" +
                    username + "/" + password + "/" + fullname + "/" + position + "/" + email + "/" +
                    address + "/" + city + "/" + phone + "/" + mobile + "/" + companyName + "/" +
                    companyLink + "/" + companyDescription;

                byte[] data = Encoding.UTF8.GetBytes(strCreateAcc);

                HttpWebRequest httpRequest = (HttpWebRequest)(WebRequest.Create(strCreateAcc));
                httpRequest.Method = "POST";
                httpRequest.ContentType = "text/xml";
                httpRequest.ContentLength = data.Length;
                Stream postStream = httpRequest.GetRequestStream();
                postStream.Write(data, 0, data.Length);

                HttpWebResponse httpResponse = (HttpWebResponse)(httpRequest.GetResponse());
                StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream());

                string strXML = ConvertSuccessSignUpXMLString();

                Response.ContentType = "text/xml";
                Response.Write(strXML);
                Response.End();
            }
            catch (System.Exception ez)
            {

            }
        }
    }

    public string ConvertSuccessSignUpXMLString()
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\" ?> <EmployerAccount></EmployerAccount>");

            XmlElement node;
            node = doc.CreateElement("SignUp");

            node.SetAttribute("IsSuccess", "true");
            node.SetAttribute("Username", username);

            doc.DocumentElement.AppendChild(node);

            return doc.InnerXml;
        }
}
